import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { userSimple, projectSimple } from '/@/api/backs/foundation/foundation';
import moment from 'moment';

export const columns: BasicColumn[] = [
  {
    title: '人员名称',
    dataIndex: 'userName',
  },
  {
    title: '项目名称',
    dataIndex: 'projectName',
  },
  {
    title: '离职时间',
    dataIndex: 'leaveTime',
    sorter: true,
    customRender: ({ record }) => {
      const time = record.leaveTime;
      return time ? moment(time * 1000).format('YYYY-MM-DD') : '-';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'userId',
    label: '人员名称',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: userSimple,
      labelField: 'nickname',
      valueField: 'id',
      placeholder: '请选择人员',
    },
  },
  {
    field: 'projectId',
    label: '项目名称',
    component: 'ApiSelect',
    colProps: { span: 8 },
    componentProps: {
      api: projectSimple,
      labelField: 'name',
      valueField: 'id',
      placeholder: '请选择项目',
    },
  },
  {
    field: 'createTime',
    label: '时间',
    component: 'RangePicker',
    colProps: { span: 8 },
    componentProps: {
      valueFormat: 'X',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'userInfo',
    label: '人员信息',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      api: userSimple,
      labelField: 'nickname',
      valueField: 'id',
      placeholder: '请选择人员',
      labelInValue: true,
    },
    ifShow: ({ values }) => {
      if (values.leaveTime) {
        return true;
      } else {
        return false;
      }
    },
  },
  {
    field: 'list',
    label: '人员信息',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      api: userSimple,
      labelField: 'nickname',
      mode: 'multiple',
      valueField: 'id',
      placeholder: '请选择人员',
      labelInValue: true,
    },
    ifShow: ({ values }) => {
      if (values.leaveTime) {
        return false;
      } else {
        return true;
      }
    },
  },
  {
    field: 'projectAll',
    label: '项目信息',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      api: projectSimple,
      labelField: 'name',
      valueField: 'id',
      placeholder: '请选择项目',
      labelInValue: true,
    },
  },
  {
    field: 'status',
    label: '是否离职',
    defaultValue: 1,
    component: 'Switch',
    colProps: { span: 8 },
    required: true,
    componentProps: {
      checkedValue: 0,
      unCheckedValue: 1,
    },
  },
  {
    field: 'leaveTime',
    label: '离开时间',
    required: true,
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'X',
    },
    ifShow: ({ values }) => (values.status == 1 ? false : true),
  },
];
